<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改登记部门')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-depRegister-edit" class="form-horizontal" AUTOCOMPLETE="OFF">
        <input name="id" id="id" type="hidden" th:value="${dep.id}"/>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门代码：</label>
                    <div class="col-sm-8">
                        <input name="depCode" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')" id="depCode"
                               class="form-control" type="text" th:value="${dep.depcode}" required/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门名称：</label>
                    <div class="col-sm-8">
                        <input name="title" id="title" class="form-control" type="text" th:value="${dep.title}"
                               required/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门简称：</label>
                    <div class="col-sm-8">
                        <input name="depAbbr" id="depAbbr" th:value="${dep.depAbbr}" class="form-control" type="text"
                               required/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门级别：</label>
                    <div class="col-sm-8">
                        <select name="depGrade" id="depGrade" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_DepGrade')}" required>
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${dep.DepGrade+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门类型：</label>
                    <div class="col-sm-8">
                        <select name="depType" id="depType" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_DepType')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${dep.DepType+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>所属公司：</label>
                    <div class="col-sm-8">
                        <select id="compId" name="compId" class="form-control" th:onchange="getbumen(this.value)">
                            <option value=""></option>
                            <option th:each="companys:${companys}" th:value="${companys.compID }"
                                    th:selected="${dep.CompId == companys.compID}"
                                    th:text="${companys.compAbbr }"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">行政上级部门：</label>
                    <div class="col-sm-8">
                        <select id="AdminId" name="AdminId" class="form-control">
                            <option value=""></option>
                            <option th:each="xjdep:${xjDep}" th:value="${xjdep.depId }"
                                    th:selected="${xjdep.depId == dep.AdminId}"
                                    th:text="${xjdep.title }"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">职能上级部门：</label>
                    <div class="col-sm-8">
                        <select id="funcationId" name="funcationId" class="form-control">
                            <option value=""></option>
                            <option th:each="xjdep:${xjDep}" th:value="${xjdep.depId }"
                                    th:selected="${xjdep.depId == dep.funcationId}"
                                    th:text="${xjdep.title }"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">部门负责人：</label>
                    <div class="col-sm-8">
                        <input name="DirectorName" id="DirectorName"
                               class="form-control" type="text" onclick="getDirector()" th:value="${dep.DirectorName}"/>
                        <input name="Director" id="Director"
                               class="form-control" type="hidden" th:value="${dep.Director}"/>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">部门分管领导：</label>
                    <div class="col-sm-8">
                        <input name="Director2Name" id="Director2Name"
                               class="form-control" type="text" onclick="getDirector2()"
                               th:value="${dep.Director2Name}"/>
                        <input name="Director2" id="Director2"
                               class="form-control" type="hidden" th:value="${dep.Director2}"/></div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">成本中心：</label>
                    <div class="col-sm-8">
                        <select name="DepCost" id="DepCost" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_DepCost')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${dep.DepCost+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>成立日期：</label>
                    <div class="col-sm-8">
                        <input name="effectDate" id="effectDate" th:value="${dep.effectDate}" class="form-control laydate-demo-1"
                               type="text"
                               required/>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门属性：</label>
                    <div class="col-sm-8">
                        <select name="DepProperty" id="DepProperty" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_DepProperty')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:selected="${dep.DepProperty+'' == dict.dictValue}"
                                    th:value="${dict.dictValue}"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">备注：</label>
                    <div class="col-sm-8">
                        <input name="remark" id="remark" th:value="${dep.remark}" class="form-control" type="text"/>
                    </div>
                </div>
            </div>
        </div>

    </form>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-suggest-js"/>
<th:block th:include="include :: bootstrap-typeahead-js"/>

<script type="text/javascript">

    var prefix = ctx + "depart/admin";

    $(function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '.laydate-demo-1',
                type: 'date'
            });
        });
    });


    function getbumen(value) {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "empentry/findDep",
            data: {
                "compID": value
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#AdminId").empty();
                $("#funcationId").empty();
                var arry = data;
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].depID
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#AdminId").append(html);
                $("#funcationId").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function getDirector() {
        $.modal.open("选择部门负责人", prefix + "/getPerson?type=Director");
    }

    function getDirector2() {
        $.modal.open("选择部门分管领导", prefix + "/getPerson?type=Director2");
    }

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-depRegister-edit").serializeArray();
            var id = $("#id").val();
            var depCode = $("#depCode").val();
            var title = $("#title").val();
            var depAbbr = $("#depAbbr").val();
            var depGrade = $("#depGrade").val();
            var depType = $("#depType").val();
            var compId = $("#compId").val();
            var AdminId = $("#AdminId").val();
            var funcationId = $("#funcationId").val();
            var Director = $("#Director").val();
            var Director2 = $("#Director2").val();
            var DepCost = $("#DepCost").val();
            var effectDate = $("#effectDate").val();
            var DepProperty = $("#DepProperty").val();
            var remark = $("#remark").val();
            if (depGrade == "" || depGrade == null) {
                $.modal.alertWarning("请选择部门级别!");
                return;
            } else if (depType == "" || depType == null) {
                $.modal.alertWarning("请选择部门类型!");
                return;
            } else if (compId == "" || compId == null) {
                $.modal.alertWarning("请选择所属公司!");
                return;
            } else if (DepProperty == "" || DepProperty == null) {
                $.modal.alertWarning("请选择部门属性!");
                return;
            }
            data.push({"name": "id", "value": id});
            data.push({"name": "depCode", "value": depCode});
            data.push({"name": "title", "value": title});
            data.push({"name": "depAbbr", "value": depAbbr});
            data.push({"name": "depGrade", "value": depGrade});
            data.push({"name": "depType", "value": depType});
            data.push({"name": "compId", "value": compId});
            data.push({"name": "AdminId", "value": AdminId});
            data.push({"name": "funcationId", "value": funcationId});
            data.push({"name": "Director", "value": Director});
            data.push({"name": "Director2", "value": Director2});
            data.push({"name": "DepCost", "value": DepCost});
            data.push({"name": "effectDate", "value": effectDate});
            data.push({"name": "DepProperty", "value": DepProperty});
            data.push({"name": "remark", "value": remark});
            $.operate.save(prefix + "/editDepAdd", data);
        }
    }

</script>

</body>
</html>